<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>探索C++14新特性：更强大、更高效的编程 | ShuangChenYue</title>
    <meta name="generator" content="VuePress 1.9.10">
    <link rel="icon" href="https://cdn.jsdelivr.net/gh/cmty256/imgs-blog@main/logo/白云.38zbldnhh180.jpg">
    <meta name="description" content="满招损，谦受益">
    <meta name="keywords" content="专注于Cpp语言的旅行者">
    
    <link rel="preload" href="/assets/css/0.styles.952d6952.css" as="style"><link rel="preload" href="/assets/js/app.67adcfd9.js" as="script"><link rel="preload" href="/assets/js/4.9aaa1650.js" as="script"><link rel="preload" href="/assets/js/1.5474518c.js" as="script"><link rel="preload" href="/assets/js/3.593d14fc.js" as="script"><link rel="preload" href="/assets/js/50.a8bc75df.js" as="script"><link rel="prefetch" href="/assets/js/10.3242746b.js"><link rel="prefetch" href="/assets/js/100.9224de43.js"><link rel="prefetch" href="/assets/js/101.f0d1b059.js"><link rel="prefetch" href="/assets/js/102.996bfc6d.js"><link rel="prefetch" href="/assets/js/103.9bfdbd6f.js"><link rel="prefetch" href="/assets/js/104.8613f283.js"><link rel="prefetch" href="/assets/js/105.aa6e809e.js"><link rel="prefetch" href="/assets/js/106.90192392.js"><link rel="prefetch" href="/assets/js/107.e82a40b7.js"><link rel="prefetch" href="/assets/js/108.994cd438.js"><link rel="prefetch" href="/assets/js/109.ec15acc2.js"><link rel="prefetch" href="/assets/js/11.c04b41c1.js"><link rel="prefetch" href="/assets/js/110.c32d8576.js"><link rel="prefetch" href="/assets/js/111.453b5d50.js"><link rel="prefetch" href="/assets/js/112.ffbdb3a4.js"><link rel="prefetch" href="/assets/js/113.12b8ad7d.js"><link rel="prefetch" href="/assets/js/114.899d2998.js"><link rel="prefetch" href="/assets/js/115.b7ad9576.js"><link rel="prefetch" href="/assets/js/116.a8394748.js"><link rel="prefetch" href="/assets/js/117.0edfe25b.js"><link rel="prefetch" href="/assets/js/118.9161b1fe.js"><link rel="prefetch" href="/assets/js/119.be59e21b.js"><link rel="prefetch" href="/assets/js/12.41437bf6.js"><link rel="prefetch" href="/assets/js/120.bcf439fb.js"><link rel="prefetch" href="/assets/js/121.c3d251b8.js"><link rel="prefetch" href="/assets/js/122.62b1caba.js"><link rel="prefetch" href="/assets/js/123.787c2ab0.js"><link rel="prefetch" href="/assets/js/124.a880746f.js"><link rel="prefetch" href="/assets/js/125.d8edfe7b.js"><link rel="prefetch" href="/assets/js/126.4ff01546.js"><link rel="prefetch" href="/assets/js/127.9416d1ff.js"><link rel="prefetch" href="/assets/js/128.01a4a7a0.js"><link rel="prefetch" href="/assets/js/129.76876665.js"><link rel="prefetch" href="/assets/js/13.922328e9.js"><link rel="prefetch" href="/assets/js/130.7f631dd9.js"><link rel="prefetch" href="/assets/js/131.c9e0fde9.js"><link rel="prefetch" href="/assets/js/132.1c04cde5.js"><link rel="prefetch" href="/assets/js/133.e8f381cd.js"><link rel="prefetch" href="/assets/js/134.03d19f8b.js"><link rel="prefetch" href="/assets/js/135.44607494.js"><link rel="prefetch" href="/assets/js/136.6a1eb3c9.js"><link rel="prefetch" href="/assets/js/137.27898fd1.js"><link rel="prefetch" href="/assets/js/138.5bc0cf54.js"><link rel="prefetch" href="/assets/js/139.c2d1addc.js"><link rel="prefetch" href="/assets/js/14.e54d7526.js"><link rel="prefetch" href="/assets/js/140.052ec8e4.js"><link rel="prefetch" href="/assets/js/141.131abb5a.js"><link rel="prefetch" href="/assets/js/142.6ba6c07b.js"><link rel="prefetch" href="/assets/js/143.5dd51d22.js"><link rel="prefetch" href="/assets/js/144.b45afca8.js"><link rel="prefetch" href="/assets/js/145.faa9fb04.js"><link rel="prefetch" href="/assets/js/146.b54c024d.js"><link rel="prefetch" href="/assets/js/147.a1223242.js"><link rel="prefetch" href="/assets/js/148.4767bcb2.js"><link rel="prefetch" href="/assets/js/149.b65ab046.js"><link rel="prefetch" href="/assets/js/15.7082a3da.js"><link rel="prefetch" href="/assets/js/150.9bd8c175.js"><link rel="prefetch" href="/assets/js/151.9f830e96.js"><link rel="prefetch" href="/assets/js/152.41cde7f0.js"><link rel="prefetch" href="/assets/js/153.f57d65e0.js"><link rel="prefetch" href="/assets/js/154.5d7c8d51.js"><link rel="prefetch" href="/assets/js/155.0ae99532.js"><link rel="prefetch" href="/assets/js/156.5a54e043.js"><link rel="prefetch" href="/assets/js/157.c25b5d40.js"><link rel="prefetch" href="/assets/js/158.aa025b46.js"><link rel="prefetch" href="/assets/js/159.47939d88.js"><link rel="prefetch" href="/assets/js/16.fc775b7b.js"><link rel="prefetch" href="/assets/js/160.f8624459.js"><link rel="prefetch" href="/assets/js/161.7a075dc2.js"><link rel="prefetch" href="/assets/js/162.1d48f266.js"><link rel="prefetch" href="/assets/js/163.5d68a99f.js"><link rel="prefetch" href="/assets/js/164.1262d0e5.js"><link rel="prefetch" href="/assets/js/165.2ccf0bdd.js"><link rel="prefetch" href="/assets/js/166.21ece4d9.js"><link rel="prefetch" href="/assets/js/167.bf8adb95.js"><link rel="prefetch" href="/assets/js/168.1cb8440d.js"><link rel="prefetch" href="/assets/js/169.1dd1e396.js"><link rel="prefetch" href="/assets/js/17.ecc7be70.js"><link rel="prefetch" href="/assets/js/170.c29ec18f.js"><link rel="prefetch" href="/assets/js/171.38820827.js"><link rel="prefetch" href="/assets/js/172.bbc8ffc6.js"><link rel="prefetch" href="/assets/js/173.470e21e7.js"><link rel="prefetch" href="/assets/js/174.3c2df318.js"><link rel="prefetch" href="/assets/js/175.d2690cdb.js"><link rel="prefetch" href="/assets/js/176.9ca64696.js"><link rel="prefetch" href="/assets/js/177.76f3271d.js"><link rel="prefetch" href="/assets/js/178.d7d9def2.js"><link rel="prefetch" href="/assets/js/179.b5644743.js"><link rel="prefetch" href="/assets/js/18.31fe7ecd.js"><link rel="prefetch" href="/assets/js/180.7592d5ef.js"><link rel="prefetch" href="/assets/js/181.5cb77d35.js"><link rel="prefetch" href="/assets/js/182.6fa5633c.js"><link rel="prefetch" href="/assets/js/183.b3a53d1b.js"><link rel="prefetch" href="/assets/js/184.3815c537.js"><link rel="prefetch" href="/assets/js/185.bcf4ab71.js"><link rel="prefetch" href="/assets/js/186.1cc02f6d.js"><link rel="prefetch" href="/assets/js/187.8b425fb7.js"><link rel="prefetch" href="/assets/js/188.44ccbd02.js"><link rel="prefetch" href="/assets/js/189.353b35e3.js"><link rel="prefetch" href="/assets/js/19.520992d5.js"><link rel="prefetch" href="/assets/js/190.c284595f.js"><link rel="prefetch" href="/assets/js/191.788ecc2d.js"><link rel="prefetch" href="/assets/js/192.712a164e.js"><link rel="prefetch" href="/assets/js/193.da58aba3.js"><link rel="prefetch" href="/assets/js/194.6b1b1f4d.js"><link rel="prefetch" href="/assets/js/195.c31d5c39.js"><link rel="prefetch" href="/assets/js/196.f6670c4d.js"><link rel="prefetch" href="/assets/js/197.5a1f50ab.js"><link rel="prefetch" href="/assets/js/2.ab565158.js"><link rel="prefetch" href="/assets/js/20.69e29cdc.js"><link rel="prefetch" href="/assets/js/21.2fd424ad.js"><link rel="prefetch" href="/assets/js/22.d4c0be54.js"><link rel="prefetch" href="/assets/js/23.4bb90ecc.js"><link rel="prefetch" href="/assets/js/24.c01be6b2.js"><link rel="prefetch" href="/assets/js/25.c8833687.js"><link rel="prefetch" href="/assets/js/26.8042b555.js"><link rel="prefetch" href="/assets/js/27.0d5fa4c0.js"><link rel="prefetch" href="/assets/js/28.f9735b8b.js"><link rel="prefetch" href="/assets/js/29.3af53626.js"><link rel="prefetch" href="/assets/js/30.5f1b56d1.js"><link rel="prefetch" href="/assets/js/31.544b2649.js"><link rel="prefetch" href="/assets/js/32.aa321988.js"><link rel="prefetch" href="/assets/js/33.6aba2c86.js"><link rel="prefetch" href="/assets/js/34.e1bbff24.js"><link rel="prefetch" href="/assets/js/35.233f76e0.js"><link rel="prefetch" href="/assets/js/36.cb773972.js"><link rel="prefetch" href="/assets/js/37.393d9c59.js"><link rel="prefetch" href="/assets/js/38.e2d530c5.js"><link rel="prefetch" href="/assets/js/39.acaf1cc0.js"><link rel="prefetch" href="/assets/js/40.358f731e.js"><link rel="prefetch" href="/assets/js/41.ded24b7e.js"><link rel="prefetch" href="/assets/js/42.b9f683c3.js"><link rel="prefetch" href="/assets/js/43.c8fb3e66.js"><link rel="prefetch" href="/assets/js/44.633142da.js"><link rel="prefetch" href="/assets/js/45.6095e772.js"><link rel="prefetch" href="/assets/js/46.421d8c7a.js"><link rel="prefetch" href="/assets/js/47.da50fe47.js"><link rel="prefetch" href="/assets/js/48.15ff5726.js"><link rel="prefetch" href="/assets/js/49.b662e624.js"><link rel="prefetch" href="/assets/js/5.c1b8a209.js"><link rel="prefetch" href="/assets/js/51.51e36ae7.js"><link rel="prefetch" href="/assets/js/52.54cc6e51.js"><link rel="prefetch" href="/assets/js/53.4173561d.js"><link rel="prefetch" href="/assets/js/54.7cab8416.js"><link rel="prefetch" href="/assets/js/55.3d7317d3.js"><link rel="prefetch" href="/assets/js/56.3c22255b.js"><link rel="prefetch" href="/assets/js/57.18e46e30.js"><link rel="prefetch" href="/assets/js/58.aad57f31.js"><link rel="prefetch" href="/assets/js/59.7897f6a7.js"><link rel="prefetch" href="/assets/js/6.3131f88a.js"><link rel="prefetch" href="/assets/js/60.5cd0051a.js"><link rel="prefetch" href="/assets/js/61.d9606403.js"><link rel="prefetch" href="/assets/js/62.aede9df0.js"><link rel="prefetch" href="/assets/js/63.2c30e554.js"><link rel="prefetch" href="/assets/js/64.18228ab7.js"><link rel="prefetch" href="/assets/js/65.27cb3fba.js"><link rel="prefetch" href="/assets/js/66.2fa6c2dc.js"><link rel="prefetch" href="/assets/js/67.d274a8df.js"><link rel="prefetch" href="/assets/js/68.3069cfcf.js"><link rel="prefetch" href="/assets/js/69.4c28600f.js"><link rel="prefetch" href="/assets/js/7.89e6165d.js"><link rel="prefetch" href="/assets/js/70.4175440c.js"><link rel="prefetch" href="/assets/js/71.2ee6b435.js"><link rel="prefetch" href="/assets/js/72.c75e3bb8.js"><link rel="prefetch" href="/assets/js/73.6f8b8211.js"><link rel="prefetch" href="/assets/js/74.6c7720cf.js"><link rel="prefetch" href="/assets/js/75.cccfb229.js"><link rel="prefetch" href="/assets/js/76.f022e5da.js"><link rel="prefetch" href="/assets/js/77.dab46206.js"><link rel="prefetch" href="/assets/js/78.ca574b2a.js"><link rel="prefetch" href="/assets/js/79.3d75e618.js"><link rel="prefetch" href="/assets/js/80.091749b1.js"><link rel="prefetch" href="/assets/js/81.14db0e21.js"><link rel="prefetch" href="/assets/js/82.8a2b1809.js"><link rel="prefetch" href="/assets/js/83.84a4b599.js"><link rel="prefetch" href="/assets/js/84.11d7c222.js"><link rel="prefetch" href="/assets/js/85.273d4388.js"><link rel="prefetch" href="/assets/js/86.fb40e20c.js"><link rel="prefetch" href="/assets/js/87.3316639e.js"><link rel="prefetch" href="/assets/js/88.dfc52200.js"><link rel="prefetch" href="/assets/js/89.8d615f6e.js"><link rel="prefetch" href="/assets/js/90.1d9f08bb.js"><link rel="prefetch" href="/assets/js/91.566813e7.js"><link rel="prefetch" href="/assets/js/92.d13c6f41.js"><link rel="prefetch" href="/assets/js/93.845c42a0.js"><link rel="prefetch" href="/assets/js/94.20a37b77.js"><link rel="prefetch" href="/assets/js/95.1a498005.js"><link rel="prefetch" href="/assets/js/96.39fa7f4b.js"><link rel="prefetch" href="/assets/js/97.50f7170e.js"><link rel="prefetch" href="/assets/js/98.dd2e15d6.js"><link rel="prefetch" href="/assets/js/99.ef7ea06a.js"><link rel="prefetch" href="/assets/js/vendors~docsearch.ae6b1de9.js">
    <link rel="stylesheet" href="/assets/css/0.styles.952d6952.css">
  </head>
  <body class="theme-mode-light">
    <div id="app" data-server-rendered="true"><div class="theme-container sidebar-open have-rightmenu"><header class="navbar blur"><div title="目录" class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><img src="https://cdn.jsdelivr.net/gh/cmty256/imgs-blog@main/logo/白云.38zbldnhh180.jpg" alt="ShuangChenYue" class="logo"> <span class="site-name can-hide">ShuangChenYue</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/" class="nav-link">首页</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="CPP语言" class="dropdown-title"><!----> <span class="title" style="display:;">CPP语言</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/pages/c5bdd8/" class="nav-link">Cpp之旅</a></li><li class="dropdown-item"><!----> <a href="/pages/279e62/" class="nav-link">Cpp专栏</a></li><li class="dropdown-item"><!----> <a href="/pages/801755/" class="nav-link">Effective_CPP</a></li><li class="dropdown-item"><!----> <a href="/pages/6b2468/" class="nav-link">muduo网络库</a></li><li class="dropdown-item"><!----> <a href="/pages/5f8c9f/" class="nav-link">Unix环境高级编程</a></li><li class="dropdown-item"><!----> <a href="/pages/3f1d21/" class="nav-link">Cpp提高编程</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="计算机基础" class="dropdown-title"><!----> <span class="title" style="display:;">计算机基础</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/pages/7b1cb2/" class="nav-link">计算机网络</a></li><li class="dropdown-item"><!----> <a href="/pages/6048a8/" class="nav-link">操作系统</a></li><li class="dropdown-item"><!----> <a href="/pages/3b34ba/" class="nav-link">数据结构</a></li><li class="dropdown-item"><!----> <a href="/pages/412fe7/" class="nav-link">Linux</a></li><li class="dropdown-item"><!----> <a href="/pages/2dcfa1/" class="nav-link">算法</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="数据库" class="dropdown-title"><!----> <span class="title" style="display:;">数据库</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/pages/efa3f2/" class="nav-link">基础篇</a></li><li class="dropdown-item"><!----> <a href="/pages/ccc445/" class="nav-link">MySql</a></li><li class="dropdown-item"><!----> <a href="/pages/54616e/" class="nav-link">Redis</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="嵌入式软件开发" class="dropdown-title"><!----> <span class="title" style="display:;">嵌入式软件开发</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/pages/d142c2/" class="nav-link">电子嵌入式通信协议</a></li><li class="dropdown-item"><!----> <a href="/pages/4c6bf3/" class="nav-link">深入浅出SSD</a></li><li class="dropdown-item"><!----> <a href="/pages/d3f36a/" class="nav-link">文件系统</a></li><li class="dropdown-item"><!----> <a href="/pages/e0cca7/" class="nav-link">汇编语言</a></li><li class="dropdown-item"><!----> <a href="/pages/fab2d7/" class="nav-link">STM32</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="开发日常" class="dropdown-title"><!----> <span class="title" style="display:;">开发日常</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/pages/e472d1/" class="nav-link">随笔（持续更新）</a></li><li class="dropdown-item"><!----> <a href="/pages/71f6ae/" class="nav-link">Git知识总结</a></li><li class="dropdown-item"><!----> <a href="/pages/db6fb8/" class="nav-link">Git备忘清单</a></li><li class="dropdown-item"><!----> <a href="/pages/e1081f/" class="nav-link">Git 创建删除远程分支</a></li><li class="dropdown-item"><!----> <a href="/pages/777b8a/" class="nav-link">nvm使用小结</a></li><li class="dropdown-item"><!----> <a href="/pages/ee770e/" class="nav-link">虚拟机固定 IP 地址</a></li><li class="dropdown-item"><!----> <a href="/pages/1ab9a6/" class="nav-link">Shell 脚本学习笔记</a></li><li class="dropdown-item"><!----> <a href="/pages/411aa4/" class="nav-link">VScode 插件 CodeGeeX 使用教程</a></li><li class="dropdown-item"><!----> <a href="/pages/0d525d/" class="nav-link">KylinV10 将项目上传至 Github教程</a></li><li class="dropdown-item"><!----> <a href="/pages/907786/" class="nav-link">KylinV10 安装 MySQL 教程（可防踩雷）</a></li><li class="dropdown-item"><!----> <a href="/pages/a2d21e/" class="nav-link">kylinV10-SP1 安装 QT</a></li><li class="dropdown-item"><!----> <a href="/pages/b561cf/" class="nav-link">高并发内存池</a></li><li class="dropdown-item"><!----> <a href="/pages/6ab6d1/" class="nav-link">USBGUARD 项目编译环境配置</a></li><li class="dropdown-item"><!----> <a href="/pages/883f02/" class="nav-link">Power_Destory 项目</a></li><li class="dropdown-item"><!----> <a href="/pages/479472/" class="nav-link">U 盘清除工具编译教程</a></li><li class="dropdown-item"><!----> <a href="/pages/9c4241/" class="nav-link">个人博客代码推送教程</a></li><li class="dropdown-item"><!----> <a href="/pages/3ad765/" class="nav-link">SVN Trunk Branches的Merge操作</a></li><li class="dropdown-item"><!----> <a href="/pages/0c0ca8/" class="nav-link">如何高效阅读嵌入式项目代码</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="前端学习" class="dropdown-title"><!----> <span class="title" style="display:;">前端学习</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/pages/99897f/" class="nav-link">HTML与CSS</a></li><li class="dropdown-item"><!----> <a href="/pages/51542d/" class="nav-link">JS学习</a></li><li class="dropdown-item"><!----> <a href="/pages/803f9d/" class="nav-link">Vue3入门</a></li><li class="dropdown-item"><!----> <a href="/pages/ca4cfb/" class="nav-link">Vue3进阶</a></li><li class="dropdown-item"><!----> <a href="/pages/50e8d3/" class="nav-link">黑马Vue3</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="MFC" class="dropdown-title"><!----> <span class="title" style="display:;">MFC</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/pages/a4b108/" class="nav-link">MFC编程随记</a></li><li class="dropdown-item"><!----> <a href="/pages/41acbd/" class="nav-link">MFC实现ini配置文件的读取</a></li><li class="dropdown-item"><!----> <a href="/pages/951a7a/" class="nav-link">MFC实现点击列表头排序</a></li><li class="dropdown-item"><!----> <a href="/pages/a8598f/" class="nav-link">贴图法美化Button按钮</a></li><li class="dropdown-item"><!----> <a href="/pages/054516/" class="nav-link">MFC使用细节</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="闪存" class="dropdown-title"><!----> <span class="title" style="display:;">闪存</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/pages/b925b8/" class="nav-link">如何高效阅读嵌入式项目代码</a></li><li class="dropdown-item"><!----> <a href="/pages/28ec23/" class="nav-link">NAND Flash</a></li><li class="dropdown-item"><!----> <a href="/pages/62bf40/" class="nav-link">ARM 处理器</a></li><li class="dropdown-item"><!----> <a href="/pages/1a9374/" class="nav-link">嵌入式基础知识-存储器</a></li><li class="dropdown-item"><!----> <a href="/pages/aac5e3/" class="nav-link">闪存存储和制造技术概述</a></li><li class="dropdown-item"><!----> <a href="/pages/8f6056/" class="nav-link">芯片IO驱动力</a></li><li class="dropdown-item"><!----> <a href="/pages/d146b8/" class="nav-link">主流先进封装技术介绍</a></li><li class="dropdown-item"><!----> <a href="/pages/16f0ba/" class="nav-link">NAND Flash基础</a></li><li class="dropdown-item"><!----> <a href="/pages/90d8d0/" class="nav-link">基于PA算法的FTL引导</a></li><li class="dropdown-item"><!----> <a href="/pages/eb672b/" class="nav-link">SD逻辑擦除和物理擦除</a></li><li class="dropdown-item"><!----> <a href="/pages/747121/" class="nav-link">NAND Flash的SDR、ONFI、DDR接口</a></li><li class="dropdown-item"><!----> <a href="/pages/1eb351/" class="nav-link">【详解】Nand Flash必看知识</a></li><li class="dropdown-item"><!----> <a href="/pages/d2512a/" class="nav-link">【两万字详解】Nand Flash必看知识</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="面经" class="dropdown-title"><!----> <span class="title" style="display:;">面经</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/pages/d69946/" class="nav-link">虎牙C++技术面经</a></li><li class="dropdown-item"><!----> <a href="/pages/29251d/" class="nav-link">金山一面复习</a></li><li class="dropdown-item"><!----> <a href="/pages/c7c01f/" class="nav-link">完美世界秋招 C++ 游戏开发面经(Cpp部分)</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="其它" class="dropdown-title"><!----> <span class="title" style="display:;">其它</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/pages/fa256e/" class="nav-link">博客搭建</a></li><li class="dropdown-item"><!----> <a href="/pages/335531/" class="nav-link">网站收藏箱</a></li></ul></div></div> <!----></nav></div></header> <div class="sidebar-mask"></div> <div class="sidebar-hover-trigger"></div> <aside class="sidebar" style="display:none;"><!----> <nav class="nav-links"><div class="nav-item"><a href="/" class="nav-link">首页</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="CPP语言" class="dropdown-title"><!----> <span class="title" style="display:;">CPP语言</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/pages/c5bdd8/" class="nav-link">Cpp之旅</a></li><li class="dropdown-item"><!----> <a href="/pages/279e62/" class="nav-link">Cpp专栏</a></li><li class="dropdown-item"><!----> <a href="/pages/801755/" class="nav-link">Effective_CPP</a></li><li class="dropdown-item"><!----> <a href="/pages/6b2468/" class="nav-link">muduo网络库</a></li><li class="dropdown-item"><!----> <a href="/pages/5f8c9f/" class="nav-link">Unix环境高级编程</a></li><li class="dropdown-item"><!----> <a href="/pages/3f1d21/" class="nav-link">Cpp提高编程</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="计算机基础" class="dropdown-title"><!----> <span class="title" style="display:;">计算机基础</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/pages/7b1cb2/" class="nav-link">计算机网络</a></li><li class="dropdown-item"><!----> <a href="/pages/6048a8/" class="nav-link">操作系统</a></li><li class="dropdown-item"><!----> <a href="/pages/3b34ba/" class="nav-link">数据结构</a></li><li class="dropdown-item"><!----> <a href="/pages/412fe7/" class="nav-link">Linux</a></li><li class="dropdown-item"><!----> <a href="/pages/2dcfa1/" class="nav-link">算法</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="数据库" class="dropdown-title"><!----> <span class="title" style="display:;">数据库</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/pages/efa3f2/" class="nav-link">基础篇</a></li><li class="dropdown-item"><!----> <a href="/pages/ccc445/" class="nav-link">MySql</a></li><li class="dropdown-item"><!----> <a href="/pages/54616e/" class="nav-link">Redis</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="嵌入式软件开发" class="dropdown-title"><!----> <span class="title" style="display:;">嵌入式软件开发</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/pages/d142c2/" class="nav-link">电子嵌入式通信协议</a></li><li class="dropdown-item"><!----> <a href="/pages/4c6bf3/" class="nav-link">深入浅出SSD</a></li><li class="dropdown-item"><!----> <a href="/pages/d3f36a/" class="nav-link">文件系统</a></li><li class="dropdown-item"><!----> <a href="/pages/e0cca7/" class="nav-link">汇编语言</a></li><li class="dropdown-item"><!----> <a href="/pages/fab2d7/" class="nav-link">STM32</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="开发日常" class="dropdown-title"><!----> <span class="title" style="display:;">开发日常</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/pages/e472d1/" class="nav-link">随笔（持续更新）</a></li><li class="dropdown-item"><!----> <a href="/pages/71f6ae/" class="nav-link">Git知识总结</a></li><li class="dropdown-item"><!----> <a href="/pages/db6fb8/" class="nav-link">Git备忘清单</a></li><li class="dropdown-item"><!----> <a href="/pages/e1081f/" class="nav-link">Git 创建删除远程分支</a></li><li class="dropdown-item"><!----> <a href="/pages/777b8a/" class="nav-link">nvm使用小结</a></li><li class="dropdown-item"><!----> <a href="/pages/ee770e/" class="nav-link">虚拟机固定 IP 地址</a></li><li class="dropdown-item"><!----> <a href="/pages/1ab9a6/" class="nav-link">Shell 脚本学习笔记</a></li><li class="dropdown-item"><!----> <a href="/pages/411aa4/" class="nav-link">VScode 插件 CodeGeeX 使用教程</a></li><li class="dropdown-item"><!----> <a href="/pages/0d525d/" class="nav-link">KylinV10 将项目上传至 Github教程</a></li><li class="dropdown-item"><!----> <a href="/pages/907786/" class="nav-link">KylinV10 安装 MySQL 教程（可防踩雷）</a></li><li class="dropdown-item"><!----> <a href="/pages/a2d21e/" class="nav-link">kylinV10-SP1 安装 QT</a></li><li class="dropdown-item"><!----> <a href="/pages/b561cf/" class="nav-link">高并发内存池</a></li><li class="dropdown-item"><!----> <a href="/pages/6ab6d1/" class="nav-link">USBGUARD 项目编译环境配置</a></li><li class="dropdown-item"><!----> <a href="/pages/883f02/" class="nav-link">Power_Destory 项目</a></li><li class="dropdown-item"><!----> <a href="/pages/479472/" class="nav-link">U 盘清除工具编译教程</a></li><li class="dropdown-item"><!----> <a href="/pages/9c4241/" class="nav-link">个人博客代码推送教程</a></li><li class="dropdown-item"><!----> <a href="/pages/3ad765/" class="nav-link">SVN Trunk Branches的Merge操作</a></li><li class="dropdown-item"><!----> <a href="/pages/0c0ca8/" class="nav-link">如何高效阅读嵌入式项目代码</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="前端学习" class="dropdown-title"><!----> <span class="title" style="display:;">前端学习</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/pages/99897f/" class="nav-link">HTML与CSS</a></li><li class="dropdown-item"><!----> <a href="/pages/51542d/" class="nav-link">JS学习</a></li><li class="dropdown-item"><!----> <a href="/pages/803f9d/" class="nav-link">Vue3入门</a></li><li class="dropdown-item"><!----> <a href="/pages/ca4cfb/" class="nav-link">Vue3进阶</a></li><li class="dropdown-item"><!----> <a href="/pages/50e8d3/" class="nav-link">黑马Vue3</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="MFC" class="dropdown-title"><!----> <span class="title" style="display:;">MFC</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/pages/a4b108/" class="nav-link">MFC编程随记</a></li><li class="dropdown-item"><!----> <a href="/pages/41acbd/" class="nav-link">MFC实现ini配置文件的读取</a></li><li class="dropdown-item"><!----> <a href="/pages/951a7a/" class="nav-link">MFC实现点击列表头排序</a></li><li class="dropdown-item"><!----> <a href="/pages/a8598f/" class="nav-link">贴图法美化Button按钮</a></li><li class="dropdown-item"><!----> <a href="/pages/054516/" class="nav-link">MFC使用细节</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="闪存" class="dropdown-title"><!----> <span class="title" style="display:;">闪存</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/pages/b925b8/" class="nav-link">如何高效阅读嵌入式项目代码</a></li><li class="dropdown-item"><!----> <a href="/pages/28ec23/" class="nav-link">NAND Flash</a></li><li class="dropdown-item"><!----> <a href="/pages/62bf40/" class="nav-link">ARM 处理器</a></li><li class="dropdown-item"><!----> <a href="/pages/1a9374/" class="nav-link">嵌入式基础知识-存储器</a></li><li class="dropdown-item"><!----> <a href="/pages/aac5e3/" class="nav-link">闪存存储和制造技术概述</a></li><li class="dropdown-item"><!----> <a href="/pages/8f6056/" class="nav-link">芯片IO驱动力</a></li><li class="dropdown-item"><!----> <a href="/pages/d146b8/" class="nav-link">主流先进封装技术介绍</a></li><li class="dropdown-item"><!----> <a href="/pages/16f0ba/" class="nav-link">NAND Flash基础</a></li><li class="dropdown-item"><!----> <a href="/pages/90d8d0/" class="nav-link">基于PA算法的FTL引导</a></li><li class="dropdown-item"><!----> <a href="/pages/eb672b/" class="nav-link">SD逻辑擦除和物理擦除</a></li><li class="dropdown-item"><!----> <a href="/pages/747121/" class="nav-link">NAND Flash的SDR、ONFI、DDR接口</a></li><li class="dropdown-item"><!----> <a href="/pages/1eb351/" class="nav-link">【详解】Nand Flash必看知识</a></li><li class="dropdown-item"><!----> <a href="/pages/d2512a/" class="nav-link">【两万字详解】Nand Flash必看知识</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="面经" class="dropdown-title"><!----> <span class="title" style="display:;">面经</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/pages/d69946/" class="nav-link">虎牙C++技术面经</a></li><li class="dropdown-item"><!----> <a href="/pages/29251d/" class="nav-link">金山一面复习</a></li><li class="dropdown-item"><!----> <a href="/pages/c7c01f/" class="nav-link">完美世界秋招 C++ 游戏开发面经(Cpp部分)</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="其它" class="dropdown-title"><!----> <span class="title" style="display:;">其它</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/pages/fa256e/" class="nav-link">博客搭建</a></li><li class="dropdown-item"><!----> <a href="/pages/335531/" class="nav-link">网站收藏箱</a></li></ul></div></div> <!----></nav>  <ul class="sidebar-links"><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>Cpp之旅</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading open"><span>Cpp专栏</span> <span class="arrow down"></span></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/pages/279e62/" class="sidebar-link">第2章 变量和基本类型</a></li><li><a href="/pages/518856/" class="sidebar-link">Cpp11新标准</a></li><li><a href="/pages/2f7f31/" aria-current="page" class="active sidebar-link">探索C++14新特性：更强大、更高效的编程</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level2"><a href="/pages/2f7f31/#_1、引言" class="sidebar-link">1、引言</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level3"><a href="/pages/2f7f31/#_1-1新的语言特性" class="sidebar-link">1.1新的语言特性</a></li><li class="sidebar-sub-header level3"><a href="/pages/2f7f31/#_1-2新库功能" class="sidebar-link">1.2新库功能</a></li></ul></li><li class="sidebar-sub-header level2"><a href="/pages/2f7f31/#_2、变量模板" class="sidebar-link">2、变量模板</a></li><li class="sidebar-sub-header level2"><a href="/pages/2f7f31/#_3、lambda-表达式的新增功能" class="sidebar-link">3、lambda 表达式的新增功能</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level3"><a href="/pages/2f7f31/#_3-1-泛化" class="sidebar-link">3.1 泛化</a></li><li class="sidebar-sub-header level3"><a href="/pages/2f7f31/#_3-2-对捕获的变量和引用进行初始化" class="sidebar-link">3.2 对捕获的变量和引用进行初始化</a></li></ul></li><li class="sidebar-sub-header level2"><a href="/pages/2f7f31/#_4、constexpr-函数可以包含多个语句" class="sidebar-link">4、constexpr 函数可以包含多个语句</a></li><li class="sidebar-sub-header level2"><a href="/pages/2f7f31/#_5、整型字面量" class="sidebar-link">5、整型字面量</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level3"><a href="/pages/2f7f31/#_5-1-二进制字面量" class="sidebar-link">5.1 二进制字面量</a></li><li class="sidebar-sub-header level3"><a href="/pages/2f7f31/#_5-2-数字分隔符" class="sidebar-link">5.2 数字分隔符</a></li></ul></li><li class="sidebar-sub-header level2"><a href="/pages/2f7f31/#_6、返回类型自动推导" class="sidebar-link">6、返回类型自动推导</a></li><li class="sidebar-sub-header level2"><a href="/pages/2f7f31/#_7、exchange" class="sidebar-link">7、exchange</a></li><li class="sidebar-sub-header level2"><a href="/pages/2f7f31/#_8、quoted" class="sidebar-link">8、quoted</a></li><li class="sidebar-sub-header level2"><a href="/pages/2f7f31/#_9、c-14-经常考到的知识点" class="sidebar-link">9、C++14 经常考到的知识点</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level3"><a href="/pages/2f7f31/#_9-1-c-14-引入了哪些新特性" class="sidebar-link">9.1 C++14 引入了哪些新特性？</a></li><li class="sidebar-sub-header level3"><a href="/pages/2f7f31/#_9-2-c-14-中-auto-关键字的用法和限制是什么" class="sidebar-link">9.2 C++14 中 auto 关键字的用法和限制是什么？</a></li><li class="sidebar-sub-header level3"><a href="/pages/2f7f31/#_9-3-c-14-中如何使用-lambda-表达式-有什么改进" class="sidebar-link">9.3 C++14 中如何使用 Lambda 表达式？有什么改进？</a></li><li class="sidebar-sub-header level3"><a href="/pages/2f7f31/#_9-4-c-14-对于-constexpr-关键字有何改进" class="sidebar-link">9.4 C++14 对于 constexpr 关键字有何改进？</a></li><li class="sidebar-sub-header level3"><a href="/pages/2f7f31/#_9-5-c-14-中提供了哪些新的标准库组件和功能" class="sidebar-link">9.5 C++14 中提供了哪些新的标准库组件和功能？</a></li><li class="sidebar-sub-header level3"><a href="/pages/2f7f31/#_9-6-在-c-14-中-变长参数模板是如何使用的" class="sidebar-link">9.6 在 C++14 中，变长参数模板是如何使用的？</a></li><li class="sidebar-sub-header level3"><a href="/pages/2f7f31/#_9-7-在-c-14-中-是否允许在-lambda-函数内定义其他函数或类" class="sidebar-link">9.7 在 C++14 中，是否允许在 lambda 函数内定义其他函数或类？</a></li><li class="sidebar-sub-header level3"><a href="/pages/2f7f31/#_9-8-c-14-是否支持原始字符串字面量-raw-string-literals-如何使用它们" class="sidebar-link">9.8 C++14 是否支持原始字符串字面量（raw string literals）？如何使用它们？</a></li><li class="sidebar-sub-header level3"><a href="/pages/2f7f31/#_9-9-在-c-14-中-std-make-unique和std-make-shared这两个函数的作用是什么" class="sidebar-link">9.9 在 C++14 中，std::makeunique和std::makeshared这两个函数的作用是什么？</a></li><li class="sidebar-sub-header level3"><a href="/pages/2f7f31/#_9-10-c-14-引入了统一初始化语法-uniform-initialization-syntax-具体有哪些变化" class="sidebar-link">9.10 C++14 引入了统一初始化语法（uniform initialization syntax），具体有哪些变化？</a></li></ul></li></ul></li><li><a href="/pages/c6fc35/" class="sidebar-link">C++17 新特性</a></li><li><a href="/pages/7dd194/" class="sidebar-link">协程</a></li><li><a href="/pages/e769c6/" class="sidebar-link">C++ 备忘清单</a></li></ul></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>Effetcive_CPP</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>muduo网络库</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>Unix环境高级编程</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>Cpp提高编程</span> <span class="arrow right"></span></p> <!----></section></li></ul> </aside> <div><main class="page"><div class="theme-vdoing-wrapper "><div class="articleInfo-wrap" data-v-06225672><div class="articleInfo" data-v-06225672><ul class="breadcrumbs" data-v-06225672><li data-v-06225672><a href="/" title="首页" class="iconfont icon-home router-link-active" data-v-06225672></a></li> <li data-v-06225672><span data-v-06225672>CPP语言</span></li><li data-v-06225672><span data-v-06225672>Cpp专栏</span></li></ul> <div class="info" data-v-06225672><div title="作者" class="author iconfont icon-touxiang" data-v-06225672><a href="javascript:;" data-v-06225672>霜晨月</a></div> <div title="创建时间" class="date iconfont icon-riqi" data-v-06225672><a href="javascript:;" data-v-06225672>2023-12-05</a></div> <!----></div></div></div> <!----> <div class="content-wrapper"><div class="right-menu-wrapper"><div class="right-menu-margin"><div class="right-menu-title">目录</div> <div class="right-menu-content"></div></div></div> <h1><img src="">探索C++14新特性：更强大、更高效的编程<!----></h1> <!----> <div class="theme-vdoing-content content__default"><h1 id="探索c-14新特性-更强大、更高效的编程"><a href="#探索c-14新特性-更强大、更高效的编程" class="header-anchor">#</a> 探索C++14新特性：更强大、更高效的编程</h1> <p>C++14并没有太大的改动，就连官方说明中也指出，C++14相对于C++11来说是一个比较小的改动，但是在很大程度上完善了C++11，所以可以说C++14就是在C++11标准上的查漏补缺。</p> <p>C++14在2014年8月18日正式批准宣布，同年12月15日正式发布release版本。本文中将就变动部分做一个总结，有需要改进和提升的地方希望大家批评指正。</p> <h2 id="_1、引言"><a href="#_1、引言" class="header-anchor">#</a> 1、引言</h2> <h3 id="_1-1新的语言特性"><a href="#_1-1新的语言特性" class="header-anchor">#</a> 1.1新的语言特性</h3> <ul><li>变量模板</li> <li>泛型 lambda</li> <li>lambda 初始化捕获</li> <li>新建/删除省略</li> <li>放宽对 constexpr 函数的限制</li> <li>二进制文字</li> <li>数字分隔符</li> <li>函数的返回类型推导</li> <li>具有默认非静态成员初始值设定项的 聚合类。</li></ul> <h3 id="_1-2新库功能"><a href="#_1-2新库功能" class="header-anchor">#</a> 1.2新库功能</h3> <ul><li><p>std::make_unique</p></li> <li><p>std::shared_timed_mutex 和 std::shared_lock</p></li> <li><p>std::整数序列</p></li> <li><p>标准::交换</p></li> <li><p>std::引用</p></li> <li><p>以及对现有图书馆设施的许多小改进，例如</p> <ul><li><p>某些算法的两范围重载</p></li> <li><p>类型特征的类型别名版本</p></li> <li><p>用户定义的basic_string、持续时间和复杂的文字</p></li> <li><p>ETC。</p></li></ul></li></ul> <h2 id="_2、变量模板"><a href="#_2、变量模板" class="header-anchor">#</a> 2、变量模板</h2> <p>在C++11 及之前，我们只有针对类和函数的模板。C++14 中，新增了变量模板：</p> <div class="language-CPP line-numbers-mode"><pre class="language-cpp"><code><span class="token keyword">template</span><span class="token operator">&lt;</span><span class="token keyword">class</span> <span class="token class-name">T</span><span class="token operator">&gt;</span>
<span class="token keyword">constexpr</span> T pi <span class="token operator">=</span> <span class="token function">T</span><span class="token punctuation">(</span><span class="token number">3.1415926535897932385L</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">template</span><span class="token operator">&lt;</span><span class="token keyword">class</span> <span class="token class-name">T</span><span class="token operator">&gt;</span>
T <span class="token function">circular_area</span><span class="token punctuation">(</span>T r<span class="token punctuation">)</span>
<span class="token punctuation">{</span>
	<span class="token keyword">return</span> pi<span class="token operator">&lt;</span>T<span class="token operator">&gt;</span> <span class="token operator">*</span>r <span class="token operator">*</span> r<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div><p>变量模板同样可以在类变量中使用：</p> <div class="language-CPP line-numbers-mode"><pre class="language-cpp"><code><span class="token keyword">template</span><span class="token operator">&lt;</span><span class="token keyword">class</span> <span class="token class-name">T</span><span class="token operator">&gt;</span>
<span class="token keyword">class</span> <span class="token class-name">X</span> <span class="token punctuation">{</span>
	<span class="token keyword">static</span> T s<span class="token punctuation">;</span>
<span class="token punctuation">}</span><span class="token punctuation">;</span>
<span class="token keyword">template</span><span class="token operator">&lt;</span><span class="token keyword">class</span> <span class="token class-name">T</span><span class="token operator">&gt;</span>
T X<span class="token operator">&lt;</span>T<span class="token operator">&gt;</span><span class="token double-colon punctuation">::</span>s <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span>

X<span class="token operator">&lt;</span><span class="token keyword">int</span><span class="token operator">&gt;</span> x_int<span class="token punctuation">;</span>
X<span class="token operator">&lt;</span><span class="token keyword">float</span><span class="token operator">&gt;</span> x_float<span class="token punctuation">;</span>

<span class="token keyword">int</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">int</span> value_int <span class="token operator">=</span> X<span class="token operator">&lt;</span><span class="token keyword">int</span><span class="token operator">&gt;</span><span class="token double-colon punctuation">::</span>s<span class="token punctuation">;</span>       <span class="token comment">// 获取 int 类型的静态成员变量值</span>
    <span class="token keyword">float</span> value_float <span class="token operator">=</span> X<span class="token operator">&lt;</span><span class="token keyword">float</span><span class="token operator">&gt;</span><span class="token double-colon punctuation">::</span>s<span class="token punctuation">;</span> <span class="token comment">// 获取 float 类型的静态成员变量值</span>

    <span class="token comment">// ...</span>
    <span class="token keyword">return</span> <span class="token number">0</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br></div></div><p>类似函数和类模板，当变量模板被引用时，则会发生实例化。</p> <h2 id="_3、lambda-表达式的新增功能"><a href="#_3、lambda-表达式的新增功能" class="header-anchor">#</a> 3、lambda 表达式的新增功能</h2> <h3 id="_3-1-泛化"><a href="#_3-1-泛化" class="header-anchor">#</a> 3.1 泛化</h3> <p>支持在 lambda 表达式中使用 auto 定义变量类型：这一特性允许 Lambda 的形参或者内部变量的类型由编译器自动推导，而不必显式指定。</p> <div class="language-CPP line-numbers-mode"><pre class="language-cpp"><code><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span> <span class="token string">&lt;iostream&gt;</span></span>
<span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span> <span class="token string">&lt;algorithm&gt;</span></span>

<span class="token keyword">int</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token comment">// Lambda 表达式 glambda，用于输出元素</span>
    <span class="token keyword">auto</span> glambda <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">(</span><span class="token keyword">auto</span><span class="token operator">&amp;</span> a<span class="token punctuation">)</span> <span class="token punctuation">{</span> std<span class="token double-colon punctuation">::</span>cout <span class="token operator">&lt;&lt;</span> a <span class="token operator">&lt;&lt;</span> <span class="token string">&quot; &quot;</span><span class="token punctuation">;</span> <span class="token punctuation">}</span><span class="token punctuation">;</span>
    <span class="token keyword">int</span> a<span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token punctuation">{</span> <span class="token number">4</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">,</span> <span class="token number">6</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">,</span> <span class="token number">7</span><span class="token punctuation">,</span> <span class="token number">5</span> <span class="token punctuation">}</span><span class="token punctuation">;</span>
    <span class="token comment">// 使用 for_each 算法遍历数组，并对每个元素调用 Lambda 表达式 glambda</span>
    std<span class="token double-colon punctuation">::</span><span class="token function">for_each</span><span class="token punctuation">(</span>a<span class="token punctuation">,</span> a <span class="token operator">+</span> <span class="token keyword">sizeof</span><span class="token punctuation">(</span>a<span class="token punctuation">)</span> <span class="token operator">/</span> <span class="token keyword">sizeof</span><span class="token punctuation">(</span><span class="token keyword">int</span><span class="token punctuation">)</span><span class="token punctuation">,</span> glambda<span class="token punctuation">)</span><span class="token punctuation">;</span>
    std<span class="token double-colon punctuation">::</span>cout <span class="token operator">&lt;&lt;</span> std<span class="token double-colon punctuation">::</span>endl<span class="token punctuation">;</span>
    <span class="token keyword">return</span> <span class="token number">0</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br></div></div><h3 id="_3-2-对捕获的变量和引用进行初始化"><a href="#_3-2-对捕获的变量和引用进行初始化" class="header-anchor">#</a> 3.2 对捕获的变量和引用进行初始化</h3> <div class="language-CPP line-numbers-mode"><pre class="language-cpp"><code>include <span class="token operator">&lt;</span>iostream<span class="token operator">&gt;</span>
<span class="token keyword">using</span> <span class="token keyword">namespace</span> std<span class="token punctuation">;</span>
<span class="token keyword">int</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token punctuation">{</span>
	<span class="token keyword">int</span> x <span class="token operator">=</span> <span class="token number">4</span><span class="token punctuation">;</span>
	<span class="token keyword">auto</span> y <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token operator">&amp;</span>r <span class="token operator">=</span> x<span class="token punctuation">,</span> x <span class="token operator">=</span> x <span class="token operator">+</span> <span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">-&gt;</span><span class="token keyword">int</span>
	<span class="token punctuation">{</span>
		r <span class="token operator">+=</span> <span class="token number">2</span><span class="token punctuation">;</span>
		<span class="token keyword">return</span> x <span class="token operator">*</span> x<span class="token punctuation">;</span>
	<span class="token punctuation">}</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> 
	cout <span class="token operator">&lt;&lt;</span> <span class="token string">&quot;x = &quot;</span> <span class="token operator">&lt;&lt;</span> x <span class="token operator">&lt;&lt;</span> <span class="token string">&quot; y = &quot;</span> <span class="token operator">&lt;&lt;</span> y <span class="token operator">&lt;&lt;</span> endl<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token comment">// 输出结果：x = 6 y = 25</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br></div></div><p><code>auto y = [&amp;r = x, x = x + 1]() -&gt; int { ... }();</code> 定义了Lambda表达式并立即调用。</p> <ul><li><code>[&amp;r = x, x = x + 1]</code>：捕获了变量 <code>x</code>，通过引用捕获了 <code>r</code>，同时对 <code>x</code> 进行了初始化，将 <code>x</code> 的值增加了1。</li> <li><code>()-&gt;int { r += 2; return x * x; }</code>：Lambda表达式的主体，对捕获的变量进行操作。<code>r</code> 是通过引用捕获的，所以对 <code>r</code> 的修改会影响到外部的 <code>x</code>。Lambda表达式返回 <code>x * x</code> 的结果。</li></ul> <h2 id="_4、constexpr-函数可以包含多个语句"><a href="#_4、constexpr-函数可以包含多个语句" class="header-anchor">#</a> 4、constexpr 函数可以包含多个语句</h2> <p>在 C++11 中，如果想使用 constexpr 方法，只能包含一个返回语句。</p> <div class="language-CPP line-numbers-mode"><pre class="language-cpp"><code><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span> <span class="token string">&lt;iostream&gt;</span></span>
<span class="token keyword">constexpr</span> <span class="token keyword">int</span> <span class="token function">square</span><span class="token punctuation">(</span><span class="token keyword">int</span> x<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> x <span class="token operator">*</span> x<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token keyword">int</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">constexpr</span> <span class="token keyword">int</span> result <span class="token operator">=</span> <span class="token function">square</span><span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// 合法的 constexpr 函数调用</span>
    <span class="token comment">// 在 C++11 中，下面的调用将导致编译错误</span>
    <span class="token comment">// constexpr int invalidResult = []() {</span>
    <span class="token comment">//     int sum = 0;</span>
    <span class="token comment">//     for (int i = 1; i &lt;= 5; ++i) {</span>
    <span class="token comment">//         sum += i;</span>
    <span class="token comment">//     }</span>
    <span class="token comment">//     return sum;</span>
    <span class="token comment">// }();</span>
    std<span class="token double-colon punctuation">::</span>cout <span class="token operator">&lt;&lt;</span> <span class="token string">&quot;Result: &quot;</span> <span class="token operator">&lt;&lt;</span> result <span class="token operator">&lt;&lt;</span> std<span class="token double-colon punctuation">::</span>endl<span class="token punctuation">;</span>
    <span class="token keyword">return</span> <span class="token number">0</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br></div></div><p>C++14 中，放宽了此要求，允许 constexpr 函数中声明变量，使用循环和条件语句等：</p> <div class="language-CPP line-numbers-mode"><pre class="language-cpp"><code><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span> <span class="token string">&lt;iostream&gt;</span></span>
<span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span> <span class="token string">&lt;cmath&gt;</span></span>
<span class="token keyword">using</span> <span class="token keyword">namespace</span> std<span class="token punctuation">;</span>
<span class="token keyword">constexpr</span> <span class="token keyword">bool</span> <span class="token function">isPrimitive</span><span class="token punctuation">(</span><span class="token keyword">int</span> number<span class="token punctuation">)</span> <span class="token punctuation">{</span>
	<span class="token keyword">if</span> <span class="token punctuation">(</span>number <span class="token operator">&lt;=</span> <span class="token number">0</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token keyword">return</span> <span class="token boolean">false</span><span class="token punctuation">;</span>
	<span class="token punctuation">}</span>
	<span class="token keyword">for</span> <span class="token punctuation">(</span><span class="token keyword">int</span> i <span class="token operator">=</span> <span class="token number">2</span><span class="token punctuation">;</span> i <span class="token operator">&lt;=</span> <span class="token function">sqrt</span><span class="token punctuation">(</span>number<span class="token punctuation">)</span> <span class="token operator">+</span> <span class="token number">1</span><span class="token punctuation">;</span> <span class="token operator">++</span>i<span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token keyword">if</span> <span class="token punctuation">(</span>number <span class="token operator">%</span> i <span class="token operator">==</span> <span class="token number">0</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
			<span class="token keyword">return</span> <span class="token boolean">false</span><span class="token punctuation">;</span>
		<span class="token punctuation">}</span>
	<span class="token punctuation">}</span>
	<span class="token keyword">return</span> <span class="token boolean">true</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token keyword">int</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
	cout <span class="token operator">&lt;&lt;</span> boolalpha <span class="token operator">&lt;&lt;</span> <span class="token function">isPrimitive</span><span class="token punctuation">(</span><span class="token number">102</span><span class="token punctuation">)</span> <span class="token operator">&lt;&lt;</span> <span class="token string">&quot; &quot;</span> <span class="token operator">&lt;&lt;</span> <span class="token function">isPrimitive</span><span class="token punctuation">(</span><span class="token number">103</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
	<span class="token keyword">return</span> <span class="token number">0</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br></div></div><p>需要注意的是，虽然C++14对<code>constexpr</code>函数的要求放宽了一些，但仍然有一些限制。例如，递归和复杂的控制流结构可能仍然无法在<code>constexpr</code>函数中使用。</p> <p>在C++11中，我们一般需要通过递归来实现相同的功能：</p> <div class="language-CPP line-numbers-mode"><pre class="language-cpp"><code><span class="token keyword">constexpr</span> <span class="token keyword">bool</span> <span class="token function">isPrimitive</span><span class="token punctuation">(</span><span class="token keyword">int</span> number<span class="token punctuation">,</span> <span class="token keyword">int</span> currentFactor<span class="token punctuation">,</span> <span class="token keyword">int</span> maxFactor<span class="token punctuation">)</span> <span class="token punctuation">{</span>
	<span class="token keyword">return</span> currentFactor <span class="token operator">==</span> maxFactor <span class="token operator">?</span> <span class="token boolean">true</span> <span class="token operator">:</span> 
			<span class="token punctuation">(</span>number <span class="token operator">%</span> currentFactor <span class="token operator">==</span> <span class="token number">0</span> <span class="token operator">?</span> <span class="token boolean">false</span> <span class="token operator">:</span> 
				<span class="token function">isPrimitive</span><span class="token punctuation">(</span>number<span class="token punctuation">,</span> currentFactor <span class="token operator">+</span> <span class="token number">1</span><span class="token punctuation">,</span> maxFactor<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token keyword">constexpr</span> <span class="token keyword">bool</span> <span class="token function">isPrimitive</span><span class="token punctuation">(</span><span class="token keyword">int</span> number<span class="token punctuation">)</span> <span class="token punctuation">{</span>
	<span class="token keyword">return</span> number <span class="token operator">&lt;=</span> <span class="token number">0</span> <span class="token operator">?</span> <span class="token boolean">false</span> <span class="token operator">:</span> <span class="token function">isPrimitive</span><span class="token punctuation">(</span>number<span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">,</span> <span class="token function">sqrt</span><span class="token punctuation">(</span>number<span class="token punctuation">)</span> <span class="token operator">+</span> <span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br></div></div><h2 id="_5、整型字面量"><a href="#_5、整型字面量" class="header-anchor">#</a> 5、整型字面量</h2> <h3 id="_5-1-二进制字面量"><a href="#_5-1-二进制字面量" class="header-anchor">#</a> 5.1 二进制字面量</h3> <p>支持使用 0b 开头的一串数字作为二进制表示的整型：</p> <div class="language-CPP line-numbers-mode"><pre class="language-cpp"><code><span class="token keyword">int</span> a <span class="token operator">=</span> <span class="token number">0b10101001110</span><span class="token punctuation">;</span> <span class="token comment">// 1358</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h3 id="_5-2-数字分隔符"><a href="#_5-2-数字分隔符" class="header-anchor">#</a> 5.2 数字分隔符</h3> <p>支持在数字中使用单引号进行分割（便于阅读）。在编译时，这些单引号会被忽略。</p> <div class="language-CPP line-numbers-mode"><pre class="language-cpp"><code><span class="token keyword">int</span> a <span class="token operator">=</span> <span class="token number">123'456'789</span><span class="token punctuation">;</span> <span class="token comment">// 123456789</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h2 id="_6、返回类型自动推导"><a href="#_6、返回类型自动推导" class="header-anchor">#</a> 6、返回类型自动推导</h2> <p>在 C++14 中，我们可以使用 auto 作为函数返回值并且不需要指明其返回类型的推导表达式</p> <div class="language-CPP line-numbers-mode"><pre class="language-cpp"><code><span class="token keyword">int</span> x <span class="token operator">=</span> <span class="token number">1</span><span class="token punctuation">;</span>
<span class="token keyword">auto</span> <span class="token function">f</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token keyword">return</span> x<span class="token punctuation">;</span> <span class="token punctuation">}</span>
<span class="token comment">/* c++11
auto f() -&gt; decltype(x) { return x; } 
*/</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><p>这种类型推导有一些限制：</p> <ol><li><p><strong>相同类型的推导：</strong> 在一个函数中，所有的返回语句必须推导出相同的类型。</p> <div class="language-cpp line-numbers-mode"><pre class="language-cpp"><code><span class="token keyword">int</span> x <span class="token operator">=</span> <span class="token number">1</span><span class="token punctuation">;</span>
<span class="token keyword">auto</span> <span class="token function">f</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token keyword">return</span> x<span class="token punctuation">;</span> <span class="token punctuation">}</span>  <span class="token comment">// 合法</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div></li> <li><p><strong>使用 <code>{}</code> 包裹的数据：</strong> 对于使用 <code>{}</code> 包裹的数据作为返回值时，无法推导其类型。</p> <div class="language-cpp line-numbers-mode"><pre class="language-cpp"><code><span class="token keyword">auto</span> <span class="token function">g</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token keyword">return</span> <span class="token punctuation">{</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">}</span><span class="token punctuation">;</span> <span class="token punctuation">}</span>  <span class="token comment">// 不合法</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div></li> <li><p><strong>虚函数和 coroutine 不能被推导：</strong> 虚函数和协程不能使用此类型推导。</p></li> <li><p><strong>函数模板中的类型推导：</strong> 函数模板中可以使用类型推导，但显式实例化和特化版本必须使用相同的返回类型描述符。</p> <div class="language-cpp line-numbers-mode"><pre class="language-cpp"><code><span class="token keyword">template</span> <span class="token operator">&lt;</span><span class="token keyword">typename</span> <span class="token class-name">T</span><span class="token operator">&gt;</span>
<span class="token keyword">auto</span> <span class="token function">h</span><span class="token punctuation">(</span>T value<span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token keyword">return</span> value<span class="token punctuation">;</span> <span class="token punctuation">}</span>

<span class="token keyword">template</span> <span class="token keyword">auto</span> <span class="token generic-function"><span class="token function">h</span><span class="token generic class-name"><span class="token operator">&lt;</span><span class="token keyword">int</span><span class="token operator">&gt;</span></span></span><span class="token punctuation">(</span><span class="token keyword">int</span><span class="token punctuation">)</span><span class="token punctuation">;</span>  <span class="token comment">// 合法</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div></li></ol> <p>这些限制是为了保证类型推导的一致性和可靠性。虽然C++14引入了更多的自动类型推导，但在一些情况下，显式指定返回类型仍然是必要的。</p> <h2 id="_7、exchange"><a href="#_7、exchange" class="header-anchor">#</a> 7、exchange</h2> <p>exchange 用于移动语义，可以使用指定的新值替换掉原值，并返回原值。其定义在C++20中被简单修改如下：</p> <div class="language-CPP line-numbers-mode"><pre class="language-cpp"><code><span class="token keyword">template</span><span class="token operator">&lt;</span><span class="token keyword">class</span> <span class="token class-name">T</span><span class="token punctuation">,</span> <span class="token keyword">class</span> <span class="token class-name">U</span> <span class="token operator">=</span> T<span class="token operator">&gt;</span>
<span class="token keyword">constexpr</span> <span class="token comment">// since C++20</span>
T <span class="token function">exchange</span><span class="token punctuation">(</span>T<span class="token operator">&amp;</span> obj<span class="token punctuation">,</span> U<span class="token operator">&amp;&amp;</span> new_value<span class="token punctuation">)</span>
<span class="token punctuation">{</span>
    T old_value <span class="token operator">=</span> std<span class="token double-colon punctuation">::</span><span class="token function">move</span><span class="token punctuation">(</span>obj<span class="token punctuation">)</span><span class="token punctuation">;</span>
    obj <span class="token operator">=</span> std<span class="token double-colon punctuation">::</span><span class="token generic-function"><span class="token function">forward</span><span class="token generic class-name"><span class="token operator">&lt;</span>U<span class="token operator">&gt;</span></span></span><span class="token punctuation">(</span>new_value<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">return</span> old_value<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br></div></div><p>其使用如下：</p> <div class="language-CPP line-numbers-mode"><pre class="language-cpp"><code><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span> <span class="token string">&lt;iostream&gt;</span></span>
<span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span> <span class="token string">&lt;vector&gt;</span></span>
<span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span> <span class="token string">&lt;utility&gt;</span></span>
<span class="token keyword">using</span> <span class="token keyword">namespace</span> std<span class="token punctuation">;</span>
<span class="token keyword">int</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
	vector<span class="token operator">&lt;</span><span class="token keyword">int</span><span class="token operator">&gt;</span> v <span class="token operator">=</span> <span class="token punctuation">{</span><span class="token number">5</span><span class="token punctuation">,</span> <span class="token number">6</span><span class="token punctuation">,</span> <span class="token number">7</span><span class="token punctuation">}</span><span class="token punctuation">;</span>
	std<span class="token double-colon punctuation">::</span><span class="token function">exchange</span><span class="token punctuation">(</span>v<span class="token punctuation">,</span> <span class="token punctuation">{</span> <span class="token number">1</span><span class="token punctuation">,</span><span class="token number">2</span><span class="token punctuation">,</span><span class="token number">3</span><span class="token punctuation">,</span><span class="token number">4</span> <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
	std<span class="token double-colon punctuation">::</span><span class="token function">copy</span><span class="token punctuation">(</span><span class="token function">begin</span><span class="token punctuation">(</span>v<span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token function">end</span><span class="token punctuation">(</span>v<span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token generic-function"><span class="token function">ostream_iterator</span><span class="token generic class-name"><span class="token operator">&lt;</span><span class="token keyword">int</span><span class="token operator">&gt;</span></span></span><span class="token punctuation">(</span>cout<span class="token punctuation">,</span> <span class="token string">&quot; &quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
	cout <span class="token operator">&lt;&lt;</span> endl<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br></div></div><h2 id="_8、quoted"><a href="#_8、quoted" class="header-anchor">#</a> 8、quoted</h2> <p>该类用于字符串转义的处理。使用 <code>out &lt;&lt; quoted(s, delim, escape)</code>的形式，可以将字符串 s 的转义格式写入输出流中；</p> <p>使用 <code>in &gt;&gt; quoted(s, delim, escape)</code> 可以将输入流去除转义格式后写入字符串 s 中。其中，delim 指明了需要转义的字符，escape 指明了修饰该转移字符的字符：</p> <div class="language-CPP line-numbers-mode"><pre class="language-cpp"><code><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span> <span class="token string">&lt;iostream&gt;</span></span>
<span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span> <span class="token string">&lt;iomanip&gt;</span></span>
<span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span> <span class="token string">&lt;sstream&gt;</span></span>
<span class="token keyword">using</span> <span class="token keyword">namespace</span> std<span class="token punctuation">;</span>
<span class="token keyword">int</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
	stringstream ss<span class="token punctuation">;</span>
	string in <span class="token operator">=</span> <span class="token string">&quot;String with spaces, and embedded \&quot;quotes\&quot; too&quot;</span><span class="token punctuation">;</span>
	string out<span class="token punctuation">;</span>
	<span class="token keyword">auto</span> show <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token operator">&amp;</span><span class="token punctuation">]</span><span class="token punctuation">(</span><span class="token keyword">const</span> <span class="token keyword">auto</span><span class="token operator">&amp;</span> what<span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token operator">&amp;</span>what <span class="token operator">==</span> <span class="token operator">&amp;</span>in
			<span class="token operator">?</span> cout <span class="token operator">&lt;&lt;</span> <span class="token string">&quot;read in     [&quot;</span> <span class="token operator">&lt;&lt;</span> in <span class="token operator">&lt;&lt;</span> <span class="token string">&quot;]\n&quot;</span>
			<span class="token operator">&lt;&lt;</span> <span class="token string">&quot;stored as   [&quot;</span> <span class="token operator">&lt;&lt;</span> ss<span class="token punctuation">.</span><span class="token function">str</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">&lt;&lt;</span> <span class="token string">&quot;]\n&quot;</span>
			<span class="token operator">:</span> cout <span class="token operator">&lt;&lt;</span> <span class="token string">&quot;written out [&quot;</span> <span class="token operator">&lt;&lt;</span> out <span class="token operator">&lt;&lt;</span> <span class="token string">&quot;]\n\n&quot;</span><span class="token punctuation">;</span>
	<span class="token punctuation">}</span><span class="token punctuation">;</span>
	ss <span class="token operator">&lt;&lt;</span> <span class="token function">quoted</span><span class="token punctuation">(</span>in<span class="token punctuation">)</span><span class="token punctuation">;</span> 
	<span class="token function">show</span><span class="token punctuation">(</span>in<span class="token punctuation">)</span><span class="token punctuation">;</span>
	ss <span class="token operator">&gt;&gt;</span> <span class="token function">quoted</span><span class="token punctuation">(</span>out<span class="token punctuation">)</span><span class="token punctuation">;</span>
	<span class="token function">show</span><span class="token punctuation">(</span>out<span class="token punctuation">)</span><span class="token punctuation">;</span>
	ss<span class="token punctuation">.</span><span class="token function">str</span><span class="token punctuation">(</span><span class="token string">&quot;&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span> 
	in <span class="token operator">=</span> <span class="token string">&quot;String with spaces, and embedded $quotes$ too&quot;</span><span class="token punctuation">;</span>
	<span class="token keyword">const</span> <span class="token keyword">char</span> delim<span class="token punctuation">{</span> <span class="token char">'$'</span> <span class="token punctuation">}</span><span class="token punctuation">;</span>
	<span class="token keyword">const</span> <span class="token keyword">char</span> escape<span class="token punctuation">{</span> <span class="token char">'%'</span> <span class="token punctuation">}</span><span class="token punctuation">;</span>
	ss <span class="token operator">&lt;&lt;</span> <span class="token function">quoted</span><span class="token punctuation">(</span>in<span class="token punctuation">,</span> delim<span class="token punctuation">,</span> escape<span class="token punctuation">)</span><span class="token punctuation">;</span>
	<span class="token function">show</span><span class="token punctuation">(</span>in<span class="token punctuation">)</span><span class="token punctuation">;</span>
	ss <span class="token operator">&gt;&gt;</span> <span class="token function">quoted</span><span class="token punctuation">(</span>out<span class="token punctuation">,</span> delim<span class="token punctuation">,</span> escape<span class="token punctuation">)</span><span class="token punctuation">;</span>
	<span class="token function">show</span><span class="token punctuation">(</span>out<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br></div></div><p><img alt="1701744385825" data-src="https://cdn.jsdelivr.net/gh/xiaose-code/Pictures@main/img/1701744385825.webp" loading="lazy" class="lazy"></p> <h2 id="_9、c-14-经常考到的知识点"><a href="#_9、c-14-经常考到的知识点" class="header-anchor">#</a> 9、C++14 经常考到的知识点</h2> <h3 id="_9-1-c-14-引入了哪些新特性"><a href="#_9-1-c-14-引入了哪些新特性" class="header-anchor">#</a> 9.1 C++14 引入了哪些新特性？</h3> <p>C++14 引入了一些新特性，包括但不限于以下内容：</p> <ol><li>通用Lambda表达式：允许在lambda函数中使用auto关键字来推导参数类型。</li> <li>自动返回类型推导：允许使用auto关键字自动推导函数返回值类型。</li> <li>初始化列表的泛型支持：可以使用auto关键字在初始化列表中推导元素类型。</li> <li>带有二进制分隔符的整数字面量：可以在整数常量中使用单撇号作为分隔符，提高可读性。</li> <li>constexpr函数的扩展：constexpr函数可以包含更多操作，例如循环和条件判断。</li> <li>变长参数模板（Variadic Templates）的改进：支持递归处理变长参数模板的展开。</li> <li>返回void类型的lambda表达式：允许定义返回void类型的lambda函数。</li></ol> <h3 id="_9-2-c-14-中-auto-关键字的用法和限制是什么"><a href="#_9-2-c-14-中-auto-关键字的用法和限制是什么" class="header-anchor">#</a> 9.2 C++14 中 auto 关键字的用法和限制是什么？</h3> <p>在 C++14 中，auto 关键字用于自动类型推导，可以根据初始化表达式的类型来确定变量的类型。它的使用和限制如下：</p> <ol><li>自动类型推导：使用 auto 关键字声明变量时，编译器会根据初始化表达式的类型自动推导出变量的类型。
auto x = 42; <em>// 推导为int型</em> auto name = &quot;John&quot;; <em>// 推导为const char*型</em></li> <li>声明时必须初始化：使用auto声明变量时，必须进行初始化。因为编译器需要根据初始化表达式来推导出变量的类型。
auto y; <em>// 错误，未初始化</em></li> <li>可与引用结合使用：auto关键字可以与引用一起使用，从而推导出引用的类型。
int a = 10; auto&amp; ref = a; <em>// 推导为int&amp;型，ref是a的引用</em></li> <li>不支持数组或函数指针：auto不能直接用于数组或函数指针的声明。但可以通过decltype结合auto来实现对数组或函数指针类型进行推导。
int arr[] = {1, 2, 3}; auto arrRef = arr; <em>// 错误，无法推导arr的数组类型</em> decltype(arr) arrType; <em>// 使用decltype获取arr的数组类型并声明arrType</em> void foo(); auto funcPtr = foo; <em>// 错误，无法推导foo的函数指针类型</em> decltype(foo)* funcPtrType; <em>// 使用decltype获取foo的函数指针类型并声明funcPtrType</em></li></ol> <p>需要注意的是，auto 在 C++14 中的用法和限制可能与之后的标准（如 C++17、C++20 等）有所不同，具体取决于编译器和所使用的标准版本。</p> <h3 id="_9-3-c-14-中如何使用-lambda-表达式-有什么改进"><a href="#_9-3-c-14-中如何使用-lambda-表达式-有什么改进" class="header-anchor">#</a> 9.3 C++14 中如何使用 Lambda 表达式？有什么改进？</h3> <p>在C++14中，使用Lambda表达式的语法与之前的C++版本相似。Lambda表达式是一种可以在代码中内联定义匿名函数的方式。</p> <p>下面是一个使用Lambda表达式的示例：</p> <div class="language-CPP line-numbers-mode"><pre class="language-cpp"><code><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span> <span class="token string">&lt;iostream&gt;</span></span>
<span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span> <span class="token string">&lt;vector&gt;</span></span>
<span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span> <span class="token string">&lt;algorithm&gt;</span></span>
<span class="token keyword">int</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    std<span class="token double-colon punctuation">::</span>vector<span class="token operator">&lt;</span><span class="token keyword">int</span><span class="token operator">&gt;</span> numbers <span class="token operator">=</span> <span class="token punctuation">{</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">,</span> <span class="token number">4</span><span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">}</span><span class="token punctuation">;</span>
    <span class="token comment">// 使用Lambda表达式进行遍历打印</span>
    std<span class="token double-colon punctuation">::</span><span class="token function">for_each</span><span class="token punctuation">(</span>numbers<span class="token punctuation">.</span><span class="token function">begin</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> numbers<span class="token punctuation">.</span><span class="token function">end</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">(</span><span class="token keyword">int</span> num<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        std<span class="token double-colon punctuation">::</span>cout <span class="token operator">&lt;&lt;</span> num <span class="token operator">&lt;&lt;</span> <span class="token string">&quot; &quot;</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">return</span> <span class="token number">0</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br></div></div><p>在 Lambda 表达式中，方括号 <code>[]</code> 用于捕获外部变量（可选）。小括号 <code>( )</code> 内指定参数列表（可选），箭头 <code>-&gt;</code> 后面指定返回类型（可选）。</p> <p>C++14 对于 Lambda 表达式有一些改进，其中最显著的改进是可以自动推导返回类型。这意味着你不需要显式地指定返回类型，编译器会根据表达式体来推断返回类型。</p> <p>以下是一个示例：</p> <div class="language-CPP line-numbers-mode"><pre class="language-cpp"><code><span class="token keyword">auto</span> lambda <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">(</span><span class="token keyword">int</span> a<span class="token punctuation">,</span> <span class="token keyword">int</span> b<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> a <span class="token operator">+</span> b<span class="token punctuation">;</span>
<span class="token punctuation">}</span><span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><p>在上述示例中，我们没有显式指定返回类型，但编译器会自动推断出返回类型为整数（因为a和b都是整数）。</p> <p>此外，在 C++14 中还引入了泛型 lambda，使得可以在 lambda 函数中使用 auto 关键字作为参数类型，更加灵活和方便。</p> <h3 id="_9-4-c-14-对于-constexpr-关键字有何改进"><a href="#_9-4-c-14-对于-constexpr-关键字有何改进" class="header-anchor">#</a> 9.4 C++14 对于 constexpr 关键字有何改进？</h3> <p>C++14 对于 <code>constexpr</code> 关键字进行了一些改进，使得其更加灵活和强大。在 C++11 中，<code>constexpr</code>只能用于表示常量表达式的函数和构造函数，而在 C++14 中，它还可以用于一些额外的情况。</p> <p>首先，在 C++14 中，<code>constexpr</code>函数可以包含一些非常量表达式的逻辑，只要这部分逻辑在运行时不会执行即可。这意味着我们可以在<code>constexpr</code>函数内使用循环、条件语句等非常量表达式的控制流程。</p> <p>其次，C++14引入了对变量模板（Variable Templates）的支持，并且允许将变量声明为<code>constexpr</code>。这样我们就可以定义并初始化一个编译期间可计算的常量变量。</p> <p>此外，在 C++14 中，对于某些标准库类型（如数组、字符串等），它们也提供了更多的支持以便于使用在编译期间计算出来的常量值。</p> <h3 id="_9-5-c-14-中提供了哪些新的标准库组件和功能"><a href="#_9-5-c-14-中提供了哪些新的标准库组件和功能" class="header-anchor">#</a> 9.5 C++14 中提供了哪些新的标准库组件和功能？</h3> <p>C++14引入了一些新的标准库组件和功能，以下是其中的一些主要特性：</p> <ol><li>std::make_unique：提供了在堆上创建 unique_ptr 对象的便捷方式。</li> <li>std::integer_sequence：支持编译时整数序列的操作，用于元编程。</li> <li>std::user_defined_literals：允许用户定义自己的字面量后缀，扩展了语言的表达能力。</li> <li>通用 lambda 表达式：允许使用 auto 参数声明参数类型，使得 lambda 表达式更加灵活。</li> <li>变长模板参数折叠（Variadic template parameter packs expansion）：可以将多个参数打包传递给模板函数或类，并且可以对它们进行展开操作。</li> <li>std::experimental 命名空间：引入了一些实验性质的标准库组件，如 optional、any、string_view 等。</li></ol> <h3 id="_9-6-在-c-14-中-变长参数模板是如何使用的"><a href="#_9-6-在-c-14-中-变长参数模板是如何使用的" class="header-anchor">#</a> 9.6 在 C++14 中，变长参数模板是如何使用的？</h3> <p>在 C++14 中，可以使用变长参数模板（Variadic Templates）来处理可变数量的函数参数。通过使用递归展开参数包的方式，可以灵活地处理任意数量的参数。</p> <p>下面是一个示例：</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>#include &lt;iostream&gt;
// 递归终止条件：当没有剩余参数时停止递归
void printArgs() {
    std::cout &lt;&lt; &quot;All arguments have been printed.&quot; &lt;&lt; std::endl;
}
// 可变参数模板：展开第一个参数并调用自身处理剩余参数
template&lt;typename T, typename... Args&gt;
void printArgs(T first, Args... args) {
    std::cout &lt;&lt; &quot;Argument: &quot; &lt;&lt; first &lt;&lt; std::endl;
    printArgs(args...); // 递归调用自身处理剩余参数
}
int main() {
    printArgs(1, &quot;Hello&quot;, 3.14, 'A');
    return 0;
}
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br></div></div><p>输出结果：</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>Argument: 1
Argument: Hello
Argument: 3.14
Argument: A
All arguments have been printed.
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><p>在上述代码中，<code>printArgs</code> 是一个可变参数模板函数。它首先处理第一个传入的参数 <code>first</code>，然后递归地调用自身处理剩余的 <code>args</code> 参数。当所有参数都被展开并打印完毕后，最终会到达递归终止条件。</p> <p>这种方式使得我们能够在编译时处理不同数量和类型的函数参数，并且可以灵活地进行操作。</p> <h3 id="_9-7-在-c-14-中-是否允许在-lambda-函数内定义其他函数或类"><a href="#_9-7-在-c-14-中-是否允许在-lambda-函数内定义其他函数或类" class="header-anchor">#</a> 9.7 在 C++14 中，是否允许在 lambda 函数内定义其他函数或类？</h3> <p>在 C++14 中，lambda 函数内是不允许定义其他函数或类的。Lambda 函数是一个匿名的函数对象，它通常用于简化代码，提供一种在局部范围内编写小型函数的方式。Lambda 函数本质上是一个闭包，它可以捕获外部作用域中的变量，并且具有与普通函数相似的行为。</p> <p>然而，在 C++17 中引入了嵌套lambda的概念，使得在 lambda 函数内定义其他 lambda 函数成为可能。在这种情况下，内层的 lambda 函数可以访问外层 lambda 函数的变量。所以如果你想要在 C++14 中定义其他函数或类，建议将其定义在 lambda 之外的范围内。</p> <h3 id="_9-8-c-14-是否支持原始字符串字面量-raw-string-literals-如何使用它们"><a href="#_9-8-c-14-是否支持原始字符串字面量-raw-string-literals-如何使用它们" class="header-anchor">#</a> 9.8 C++14 是否支持原始字符串字面量（raw string literals）？如何使用它们？</h3> <p>是的，C++14 支持原始字符串字面量（raw string literals）。</p> <p>原始字符串字面量可以用来表示包含特殊字符（例如转义序列和引号）的字符串，而无需使用转义符号。它们由R&quot;delim(raw_characters)delim&quot;的语法表示，其中delim可以是任何非空字符序列，并且在开始和结束位置上必须匹配。</p> <p>以下是一个示例：</p> <div class="language-CPP line-numbers-mode"><pre class="language-cpp"><code><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span> <span class="token string">&lt;iostream&gt;</span></span>
<span class="token keyword">int</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">const</span> <span class="token keyword">char</span><span class="token operator">*</span> str1 <span class="token operator">=</span> <span class="token raw-string string">R&quot;(Hello \n World!)&quot;</span><span class="token punctuation">;</span>
    std<span class="token double-colon punctuation">::</span>cout <span class="token operator">&lt;&lt;</span> str1 <span class="token operator">&lt;&lt;</span> std<span class="token double-colon punctuation">::</span>endl<span class="token punctuation">;</span>  <span class="token comment">// 输出：Hello \n World!</span>
    <span class="token keyword">const</span> <span class="token keyword">char</span><span class="token operator">*</span> str2 <span class="token operator">=</span> <span class="token raw-string string">R&quot;###(This is a &quot;quoted&quot; string.)###&quot;</span><span class="token punctuation">;</span>
    std<span class="token double-colon punctuation">::</span>cout <span class="token operator">&lt;&lt;</span> str2 <span class="token operator">&lt;&lt;</span> std<span class="token double-colon punctuation">::</span>endl<span class="token punctuation">;</span>  <span class="token comment">// 输出：This is a &quot;quoted&quot; string.</span>
    <span class="token keyword">return</span> <span class="token number">0</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br></div></div><p>在上面的示例中，我们使用了原始字符串字面量来创建包含特殊字符的字符串，而不需要使用额外的转义符号。</p> <h3 id="_9-9-在-c-14-中-std-make-unique和std-make-shared这两个函数的作用是什么"><a href="#_9-9-在-c-14-中-std-make-unique和std-make-shared这两个函数的作用是什么" class="header-anchor">#</a> 9.9 在 C++14 中，std::make_unique和std::make_shared这两个函数的作用是什么？</h3> <p>在 C++14 中，<code>std::make_unique</code>和<code>std::make_shared</code>是用于创建智能指针的函数模板。</p> <ul><li><code>std::make_unique</code>：用于创建一个<code>std::unique_ptr</code>对象，它拥有独占所有权的动态分配对象。这个函数接受参数并返回一个<code>std::unique_ptr</code>，它会自动管理内存释放。示例：</li></ul> <div class="language- line-numbers-mode"><pre class="language-text"><code>auto ptr = std::make_unique&lt;int&gt;(42);
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li><code>std::make_shared</code>：用于创建一个<code>std::shared_ptr</code>对象，它可以被多个指针共享的动态分配对象。这个函数接受参数并返回一个<code>std::shared_ptr</code>，它使用引用计数来管理内存释放。示例：</li></ul> <div class="language- line-numbers-mode"><pre class="language-text"><code>auto ptr = std::make_shared&lt;int&gt;(42);
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>这两个函数可以减少手动进行资源管理的工作量，并提供了更安全、更简洁的方式来处理动态分配对象。</p> <h3 id="_9-10-c-14-引入了统一初始化语法-uniform-initialization-syntax-具体有哪些变化"><a href="#_9-10-c-14-引入了统一初始化语法-uniform-initialization-syntax-具体有哪些变化" class="header-anchor">#</a> 9.10 C++14 引入了统一初始化语法（uniform initialization syntax），具体有哪些变化？</h3> <p>C++14 引入了统一初始化语法（uniform initialization syntax），它允许使用一种更统一和一致的方式进行初始化。具体的变化包括以下几个方面：</p> <ol><li>初始化列表（initializer list）：可以使用花括号 <code>{}</code> 来初始化对象，无论是简单类型还是复杂类型。例如：
int num{ 42 }; std::vector vec{ 1, 2, 3 };</li> <li>自动类型推导：在使用统一初始化语法时，编译器可以自动推导出变量的类型。
auto value{ 3.14 }; <em>// 推导为 double 类型</em> auto str{ &quot;Hello&quot; }; <em>// 推导为 const char[6] 类型</em></li> <li>统一构造函数调用语法：通过统一初始化语法，可以直接调用类的构造函数进行对象的创建。
class MyClass { public: MyClass(int value) { <em>/* 构造函数实现 */</em> } <em>// ...</em> }; MyClass obj{ 42 }; <em>// 调用构造函数创建对象</em></li> <li>空初始化：可以使用 <code>{}</code> 或 <code>()</code> 进行空初始化，不再需要显式地指定默认值。
int num{}; <em>// 初始化为0</em> std::string str{}; <em>// 初始化为空字符串</em></li></ol> <p>这些变化使得初始化更加灵活和一致，并且提供了更强大的类型推导能力。注意，在使用统一初始化语法时，要注意类型的精确匹配和可能的隐式转换。</p></div></div> <!----> <div class="page-edit"><!----> <!----> <div class="last-updated"><span class="prefix">上次更新:</span> <span class="time">2024/6/3 14:54:44</span></div></div> <div class="page-nav-wapper"><div class="page-nav-centre-wrap"><a href="/pages/518856/" class="page-nav-centre page-nav-centre-prev"><div class="tooltip">Cpp11新标准</div></a> <a href="/pages/c6fc35/" class="page-nav-centre page-nav-centre-next"><div class="tooltip">C++17 新特性</div></a></div> <div class="page-nav"><p class="inner"><span class="prev">
        ←
        <a href="/pages/518856/" class="prev">Cpp11新标准</a></span> <span class="next"><a href="/pages/c6fc35/">C++17 新特性</a>→
      </span></p></div></div></div> <!----></main></div> <div class="footer"><!----> 
  Theme by
  <a href="https://github.com/xugaoyi/vuepress-theme-vdoing" target="_blank" title="本站主题">Vdoing</a> 
    | Copyright © 2023-2025
    <span>霜晨月</span></div> <div class="buttons"><div title="返回顶部" class="button blur go-to-top iconfont icon-fanhuidingbu" style="display:none;"></div> <div title="去评论" class="button blur go-to-comment iconfont icon-pinglun" style="display:none;"></div> <div title="主题模式" class="button blur theme-mode-but iconfont icon-zhuti"><ul class="select-box" style="display:none;"><li class="iconfont icon-zidong">
          跟随系统
        </li><li class="iconfont icon-rijianmoshi">
          浅色模式
        </li><li class="iconfont icon-yejianmoshi">
          深色模式
        </li><li class="iconfont icon-yuedu">
          阅读模式
        </li></ul></div></div> <!----> <!----> <!----></div><div class="global-ui"><canvas id="vuepress-canvas-cursor"></canvas></div></div>
    <script src="/assets/js/app.67adcfd9.js" defer></script><script src="/assets/js/4.9aaa1650.js" defer></script><script src="/assets/js/1.5474518c.js" defer></script><script src="/assets/js/3.593d14fc.js" defer></script><script src="/assets/js/50.a8bc75df.js" defer></script>
  </body>
</html>
